<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>canvas测试</title>
    <style>
        #app{
            width: 500px;
            height: 500px;
        }
    </style>
</head>
<body>
    <canvas id="app"></canvas>
    <script>
        function draw (id) {
            const canvas = document.getElementById(id);
            const context = canvas.getContext('2d');
            context.fillStyle = 'rgb(0, 0, 255)';
            context.fillRect(0, 0, canvas.width, canvas.height);
            context.fillStyle = 'rgb(255, 255, 0)';
            context.fillRect(10, 20, 50, 50);
            const data = canvas.toDataURL('image/jpeg');
            console.log(data);
        }
        draw('app')
    </script>
</body>
</html>